import { constantRoutes, asyncRoutes } from "@/router"

const state = {
    routes: []
}
const mutations = {
    setRoutes(state, data) {
        // data 是筛选过后的动态路由
        // 加上原来的静态路由, 就等于最终应该显示的菜单
        state.routes = [...constantRoutes, ...data]
    }
}
const actions = {
    filterList(store, data) {
        // console.log(data);
        // console.log(asyncRoutes);
        const routes = asyncRoutes.filter(item => data.indexOf(item.name) !== -1)
        // console.log(routes);

        // 将筛选的结果,经过 Mutations 拼接菜单交给 state
        // store.commit('setRoutes', routes)
        store.commit('setRoutes', routes)
        return routes
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}